package vaccine.appointment.system.vaccine.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vaccine.appointment.system.common.annotation.AutoWrapResult;
import vaccine.appointment.system.common.annotation.RequireRole;
import vaccine.appointment.system.user.enums.IdentityInfoEnum;
import vaccine.appointment.system.vaccine.service.VaccineService;
import vaccine.appointment.system.vaccine.vo.AddVaccineRequest;
import vaccine.appointment.system.vaccine.vo.UpdateVaccineRequest;
import vaccine.appointment.system.vaccine.vo.VaccineListVO;

import javax.validation.Valid;

/**
 * 管理员疫苗管理控制器
 */
@AutoWrapResult
@RequestMapping("/admin/vaccine")
@RestController
@RequireRole({IdentityInfoEnum.SUPER_ADMIN})
public class AdminVaccineController {

    @Autowired
    private VaccineService vaccineService;

    /**
     * 添加疫苗
     * @param request 添加疫苗请求
     * @return 是否成功
     */
    @PostMapping
    public Boolean addVaccine(@Valid @RequestBody AddVaccineRequest request) {
        return vaccineService.addVaccine(request);
    }

    /**
     * 更新疫苗信息
     * @param id 疫苗ID
     * @param request 更新疫苗请求
     * @return 是否成功
     */
    @PutMapping("/{id}")
    public Boolean updateVaccine(
            @PathVariable Integer id,
            @Valid @RequestBody UpdateVaccineRequest request) {
        return vaccineService.updateVaccine(id, request);
    }

    /**
     * 删除疫苗
     * @param id 疫苗ID
     * @return 是否成功
     */
    @DeleteMapping("/{id}")
    public Boolean deleteVaccine(@PathVariable Integer id) {
        return vaccineService.deleteVaccine(id);
    }

    /**
     * 查询疫苗列表（包含已过期的）
     * @param type 疫苗类型（可选）
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 分页数据
     */
    @GetMapping("/list")
    public Page<VaccineListVO> getVaccineList(
            @RequestParam(required = false) Integer type,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return vaccineService.getAllVaccineList(type, pageNum, pageSize);
    }
}

